//
//  VCOfSecond.m
//  UI09_UITabBarController
//
//  Created by Scott on 16/5/13.
//  Copyright © 2016年 Scott. All rights reserved.
//

#import "VCOfSecond.h"

@interface VCOfSecond ()

@property (nonatomic, retain) UIButton *button;
@property (nonatomic, retain) UITextField *tf;

@end

@implementation VCOfSecond

- (void)dealloc {
    [_button release];
    [_tf release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self configTabBarItem];
        
    }
    return self;
    
    
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createTextField];
}


- (void)configTabBarItem {
    self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"地图" image:[UIImage imageNamed:@"ditu"] tag:200];
    
}


#pragma mark - 本地存储.
- (void)createTextField {
    
    self.tf = [[UITextField alloc] initWithFrame:CGRectMake(20, 100, 300, 40)];
    [self.view addSubview:self.tf];
    [_tf release];
    
    self.tf.backgroundColor = [UIColor cyanColor];

    
    self.button = [UIButton buttonWithType:UIButtonTypeSystem];
    
    self.button.frame = CGRectMake(50, 200, 200, 40);
    
    [self.button setTitle:@"保存" forState:UIControlStateNormal];
    
    [self.view addSubview:self.button];
    
    self.button.backgroundColor = [UIColor yellowColor];
    
    [self.button addTarget:self action:@selector(comfirmAction) forControlEvents:UIControlEventTouchUpInside];
}
- (void)comfirmAction {
    
    // 获取要保存的数据
    NSString *str = self.tf.text;
    
    
    // 获取/Document 目录路径.
    NSString *pathOfDocument =[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
    
    
    NSString *pathOfFile = [pathOfDocument stringByAppendingPathComponent:@"use.txt"];
    
    //Core API
    [str writeToFile:pathOfFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
}



- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    [super touchesEnded:touches withEvent:event];
    [self.view endEditing:YES];
}









@end
